#    pyPastebot 0.32 beta by goldenwolf djaswal@ryerson.ca 
#    Special thanks to warg for all his contribution
#    pyPastebot is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    pyPastebot is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os, sys, urllib, time

class Pastebin:

    def __init__(self, paste_code, paste_name=None, paste_email=None, paste_subdomain=None, paste_expire_date=None, paste_format=None):
        if paste_code:
			self.paste_code = paste_code
        if paste_name:
            self.paste_name = paste_name
        if paste_email:
            self.paste_email = paste_email
        if paste_subdomain:
            self.paste_subdomain = paste_subdomain
        if paste_expire_date:
            self.paste_expire_date = paste_expire_date
        if paste_format:
            self.paste_format = paste_format			
			
    def submit(self):
        if not self.paste_code:
            return
	opts = {"paste_code": self.paste_code,
                "paste_name": self.paste_name,
                "paste_email": self.paste_email,
                "paste_subdomain": self.paste_subdomain,
                "paste_expire_date": self.paste_expire_date,
                "paste_format": self.paste_format}
        
        f = urllib.urlopen("http://www.pastebin.com/api_public.php",
                           urllib.urlencode(opts))
        url = f.read()
        f.close()
        return url
 
# For Testing purposes
def main():
    if len(sys.argv) == 2:
        filename = sys.argv[1]
        try:
            f = open(filename, "r")
            paste_code = f.read()
            f.close()
        except IOError:
            sys.exit(3)
    else:
        sys.exit(2)

    pastebin = Pastebin(paste_code)
    url = pastebin.submit()
    print url
    sys.exit(2)
    
if __name__ == "__main__":
    main()